<template>
  <indexMerge>
    <div class="container">
      <!-- 面包屑导航 -->
      <XtxBread>
        <XtxBreadItem path="/">首页</XtxBreadItem>
        <transition name="fade-right" mode="out-in">
          <XtxBreadItem :key="needOneArr?.id">
            {{ needOneArr?.name }}
          </XtxBreadItem>
        </transition>
      </XtxBread>
      <!-- 一级分类轮播图 -->
      <CategoryCarousel />
      <!-- 一级分类 -->
      <ShowSubCategoryList :needOneArr="needOneArr" v-if="needOneArr" />
      <!-- 一级分类推荐商品 -->
      <RecommendGoods />
    </div>
  </indexMerge>
</template>

<script>
import indexMerge from "../../components/currency/indexMerge";
import CategoryCarousel from "../../components/category/CategoryCarousel";
import ShowSubCategoryList from "../../components/category/ShowSubCategoryList";
import RecommendGoods from "../../components/category/RecommendGoods";
import { useStore } from "vuex";
import { useRoute } from "vue-router";
import { computed } from "vue";

export default {
  name: "oneCategory",
  setup() {
    const store = useStore();
    const route = useRoute();

    // 获取所点击的一级导航数据
    let needOneArr = computed(() => {
      return store.state.category.list.find((item) => {
        return item.id === route.params.id;
      });
    });

    return {
      needOneArr,
    };
  },
  components: {
    indexMerge,
    CategoryCarousel,
    ShowSubCategoryList,
    RecommendGoods,
  },
};
</script>

<style></style>
